var TweenController = require('geoTweenMoveTo');

var TweenData = cc.Class({
    name: 'geoTweenData',

    properties: {
        tweenController: {
            default: null,
            type: TweenController,
            tooltip: '空间变化控制器（留空则使用默认控制器）'
        },
        tweenToNode: {
            default: null,
            type: cc.Node,
            tooltip: '变换的参考节点'
        },
        tweenDuration: {
            default: 0,
            type: cc.Float,
            tooltip: '变换需要的时间（-1则采用动画的播放时间）'
        },
        tweenPosition: {
            default: true,
            tooltip: '是否变换位置'
        },
        tweenRotation: {
            default: false,
            tooltip: '是否变换旋转'
        },
        tweenScale: {
            default: false,
            tooltip: '是否变换缩放'
        },
        tweenCompleteEvents: {
            default: [],
            type: [cc.Component.EventHandler],
            tooltip: '变换完成后回调'
        },
    },
    /**
     * 
     * @param {Function} complete 
     * @param {geoTweenMoveTo} controller 
     * @param {cc.Event} event 
     * @param {float} extraDuration 
     */
    play(complete, controller, event, extraDuration){
        var tc = controller || this.tweenController;
        extraDuration = extraDuration || 0;
        //
        if (tc){
            
            tc.doTweenToNode(
                this.tweenToNode || tc.node,
                (this.tweenDuration < 0) ? extraDuration : this.tweenDuration,
                (() => {
                    cc.Component.EventHandler.emitEvents(this.tweenCompleteEvents, event, this);
                    complete && complete();
                }).bind(this),
                this.tweenPosition,
                this.tweenScale,
                this.tweenRotation
            );
        }
    }
});

module.exports = TweenData;
